package com.cbgolf.oa.activity.publiz;


import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
import android.support.v7.app.AppCompatActivity;
import android.view.WindowManager;
import com.cbgolf.oa.R;
import com.cbgolf.oa.user.UserData;
import com.cbgolf.oa.util.ClassUtil;
import com.cbgolf.oa.util.ScreenUtil;
import com.cbgolf.oa.widget.autolayout.utils.AutoUtil;

/**
 * @author seiya
 * @date 2016/11/2
 */
public class LoadingActivity extends AppCompatActivity {

  Handler handler = new Handler();

  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
        WindowManager.LayoutParams.FLAG_FULLSCREEN);
    AutoUtil
        .setSize(this, Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP,
            ScreenUtil.getWidth(),
            ScreenUtil.getHeight());
    setContentView(R.layout.a_loading);
  }

  @Override
  protected void onDestroy() {
    super.onDestroy();
  }

  @Override
  protected void onResume() {
    super.onResume();
    startMain(1800);
  }

  //启动主页面
  private void startMain(int time) {
    handler.postDelayed(() -> {
      if (null == UserData.getUser()) {
        ClassUtil.startActivity(this, LoginActivity.class);
      } else {
        ClassUtil.startActivity(this, MainActivity.class);
      }
      finish();
    }, time);
  }


}